package com.gagakuai.test;

import sun.misc.Unsafe;

/*
 * @program: settement
 * @description:
 * @author: houhong
 * @create: 2022-11-11 10:51
 */
public class InnerCas {

    private static Integer state;
    private static final Unsafe unsafe = null;


    private static long stateOffset;


    public final boolean compareAndSwapState(int oldVal, int newVal) {
        return unsafe.compareAndSwapInt(this, stateOffset, oldVal, newVal);
    }


    static {
        try {
            stateOffset = unsafe.objectFieldOffset(InnerCas.class.getDeclaredField("state"));
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }

    }

}